//
//  OrderListViewController.m
//  Best
//
//  Created by iDeneb on 7/25/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "OrderListViewController.h"
#import "EditSettingsViewController.h"
#import "EditSettingCell.h"
#import "OrderDetailViewController.h"

@implementation OrderListViewController
#define ROW_HEIGHT 60
@synthesize myscrollView;


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
 // Custom initialization
 }
 return self;
 }
*/

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */


 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {
	 [super viewDidLoad];

 }
 

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	
	return 3;
}

- (IBAction)done:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
    //if ([delegate respondsToSelector:@selector(setupViewController:didFinishSetupWithInfo:)]) {
    //    [delegate setupViewController:self didFinishSetupWithInfo:setupInfo];
    //}
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *today_test = NSLocalizedString(@"order_no", @"");
	today_test = [today_test stringByAppendingString:@"  "];
	today_test = [today_test stringByAppendingString:NSLocalizedString(@"from_address", @"")];
	today_test = [today_test stringByAppendingString:@"   "];
	today_test = [today_test stringByAppendingString:NSLocalizedString(@"to_address", @"")];
	today_test = [today_test stringByAppendingString:@"   "];
	today_test = [today_test stringByAppendingString:NSLocalizedString(@"state", @"")];
	
	return today_test;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    EditSettingCell *cell = (EditSettingCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[EditSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	
	
	switch (indexPath.row) {
		
		case 0:{
			NSString *today_test = NSLocalizedString(@"SO-001", @"");
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"xi_an", @"")];
			today_test = [today_test stringByAppendingString:@"    "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"hang_zhou", @"")];
			today_test = [today_test stringByAppendingString:@"    "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"success", @"")];
			
			[cell setText:today_test];
		}
			//[cell setTextFieldToEdit:self.serverTextField];
			//[[cell contentView] addSubview:self.serverTextField];
			//[cell setTextFieldToEdit:self.serverTextField];
			break;
		case 1:{
			NSString *today_test = NSLocalizedString(@"SO-002", @"");
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"guang_zhou", @"")];
			today_test = [today_test stringByAppendingString:@"    "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"hang_zhou", @"")];
			today_test = [today_test stringByAppendingString:@"    "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"success", @"")];
			
			[cell setText:today_test];
		}
			//[cell setText:NSLocalizedString(@"SO-002 (hangzhou/qingdao/transfer)", @"")];
			break;
		case 2:{
			NSString *today_test = NSLocalizedString(@"SO-003", @"");
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"shang_hai", @"")];
			today_test = [today_test stringByAppendingString:@"    "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"guang_zhou", @"")];
			today_test = [today_test stringByAppendingString:@"    "];
			today_test = [today_test stringByAppendingString:NSLocalizedString(@"success", @"")];
			
			[cell setText:today_test];
		}
			//[cell setText:NSLocalizedString(@"SO-003 (qingdao/jinan/failed)", @"")];
			break;
			
		default:
			break;
	}
    // Configure the cell...
    
    return cell;
}



// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}



#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
	OrderDetailViewController *detailViewController = nil;
	switch (indexPath.row) {
		case 0:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			break;
		case 1:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			break;
		case 2:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			
			break;
		case 3:
			detailViewController = [[OrderDetailViewController alloc]initWithNibName:@"OrderDetailView" bundle:nil];
			break;
			
		default:
			break;
	}
	[self.navigationController pushViewController:detailViewController animated:YES];
	[detailViewController release];
}

#pragma mark -
#pragma mark Configuring table view cells

#define NAME_TAG 1
#define TIME_TAG 2
#define IMAGE_TAG 3


#define LEFT_COLUMN_OFFSET 10.0
#define LEFT_COLUMN_WIDTH 100

#define MIDDLE_COLUMN_OFFSET 120
#define MIDDLE_COLUMN_WIDTH 120

#define RIGHT_COLUMN_OFFSET 220.0

#define MAIN_FONT_SIZE 18.0
#define LABEL_HEIGHT 26.0

#define IMAGE_SIDE 30



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}


- (void) viewWillAppear:(BOOL)animated{
	NSLog(@"question view will appear");
	[myscrollView reloadData];
	[self.view setNeedsDisplay];
	
}


- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end


